package com.mirzabros.chexmo;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebSettings.RenderPriority;
import android.widget.Button;

import com.mirzabros.chexmo.contant.Chexmo_Urls;

public class Chexmo_TermsAndConditions_WebView extends Activity {
    private WebView webView;

    private ProgressDialog progdialod;
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setProgressBarIndeterminateVisibility(true); 
        
        setContentView(R.layout.chexmo_webview);
        
        Button btnlogouyt = (Button)findViewById(R.id.back);
        btnlogouyt.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				onBackPressed();
				
			}
		});
        
        webView = (WebView) findViewById(R.id.webView);
        
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(webView.getWindowToken(), 0);
        
        
        webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        webView.setPadding(0, 0, 0, 0);
        webView.setHorizontalScrollBarEnabled(false);
        webView.setInitialScale(50);
        
        WebSettings webSettings = webView.getSettings();
        
        webSettings.setRenderPriority(RenderPriority.HIGH);
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        
        if (Build.VERSION.SDK_INT >= 11){
        	webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }
        
        webSettings.setJavaScriptEnabled(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setUseWideViewPort(true);
        
        webSettings.setAllowUniversalAccessFromFileURLs(true);
        webSettings.setAllowFileAccessFromFileURLs(true);
        webSettings.setDomStorageEnabled(true);

        webView.loadUrl(Chexmo_Urls.WebView_TermsAndConditions);
        webView.setWebViewClient(new MyWebViewClient(Chexmo_Urls.WebView_TermsAndConditions));
        
       

    }
    
    private class MyWebViewClient extends WebViewClient {
    	
    	//PRIYAN - User WebView Code For Constructor **Do Not Change
    	
    	private String NumberURL;
    	
    	public MyWebViewClient(String numberurl) {
    		Log.e("Constructor of me", "Constructor");
    		NumberURL = numberurl;
		}
    	
    	@Override
        public boolean shouldOverrideUrlLoading(WebView webview, String url){
                webview.loadUrl(url);
                setProgressBarIndeterminateVisibility(true);
                                return true;

            }
    	
    	@Override
    	public void onPageStarted(WebView view, String url, Bitmap favicon) {
    		Log.e("onPageStarted", "onPageStarted");
    		progdialod = ProgressDialog.show(Chexmo_TermsAndConditions_WebView.this, "", "Please Wait",true,false);
    	}
        
        @Override
        public void onPageFinished(WebView view, String url) {
        	
        	Log.e("NumberURL This Called", NumberURL);
            Log.e("url", url);
            progdialod.dismiss();
            
            setProgressBarIndeterminateVisibility(false);
            
          if (url.equals(Chexmo_Urls.WebView_BackURL)) {
        	  Log.e("In IF", "In IF");
            	
            	finish();
            	
                 //InputMethodManager inputMethodManager = (InputMethodManager)  getSystemService(Activity.INPUT_METHOD_SERVICE);
                 //inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
            
          }
        }
        
      //PRIYAN-User WebView Code For Constructor **Do Not Change
    }	
 
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(event.getAction() == KeyEvent.ACTION_DOWN){
            switch(keyCode)
            {
            case KeyEvent.KEYCODE_BACK:
                if(webView.canGoBack()){
                	webView.goBack();
                }else{
                    finish();
                }
                return true;
            }

        }
        return super.onKeyDown(keyCode, event);
    }
        
    
protected void onSaveInstanceState(Bundle outState) {
   //webView.saveState(outState);
}

@Override
public void onConfigurationChanged(Configuration newConfig){        
    super.onConfigurationChanged(newConfig);
}


}
